using System;
using System.Collections.Generic;
using System.Text;

using IGlobalist.Cms.Model;
using IGlobalist.Cms.DataAccess;

namespace IGlobalist.Cms.Bll
{
    public class TemplateController : BaseController
    {
        private static ITemplate ConvertCmsObject2Template(ICmsObject obj)
        {
            ITemplate template = new Template();
            template.FromCmsObject(obj);
            return template;
        }
        private static IList<ITemplate> ConvertListObject2ListTemplates(IList<ICmsObject> list)
        {
            IList<ITemplate> templates = new List<ITemplate>();
            if (list != null)
            foreach (ICmsObject obj in list)
            {
                templates.Add(ConvertCmsObject2Template(obj));
            }

            return templates;
        }


        public static ITemplate GetTemplate(long id)
        {
            return ConvertCmsObject2Template(_Ds.GetObject(id));
        }

        public static IList<ITemplate> GetTemplateListByClass(long classID)
        {
            return ConvertListObject2ListTemplates(_Ds.GetObjectListByClassID(classID));
        }

        public static long InsertTemplate(ITemplate template)
        {
            //template.ExtPropertyList
            return _Ds.InsertObject((ICmsObject)template);
        }


        public static void UpdateTemplate(ITemplate template)
        {
            _Ds.UpdateObject((ICmsObject)template);
        }

        public static void DeleteTemplate(long id)
        {
            _Ds.DeleteObject(id);
        }
    }
}
